import {storeBindingsBehavior} from "mobx-miniprogram-bindings";
import cart from "../../../../store/cart";
Component({
  options: {
    addGlobalClass: true
  },
  behaviors: [storeBindingsBehavior],
  storeBindings: [{
    store: cart,
    fields: ['cartList', 'num', 'totalFee', 'shopId'],
    actions: ['addCart', 'reduceCart', 'clearCart'],
  }],
  data: {
    showDetail: false
  },
  methods: {
    handleRevertShowStatus() {
      this.setData({showDetail: !this.data.showDetail})
    },
    handleStop() {
      return true;
    },
    handleClearCart() {
      wx.showModal({
        title: "",
        content: "清空购物车",
        confirmText: "清空",
        showCancel: true,
        success: (res) => {
          if (res.confirm) {
            this.clearCart();
            this.setData({showDetail: false})
          }
        }
      });
    },
    handleToPay() {
      this.triggerEvent('pay')
    },
    handleOp(e) {
      let {op, item} = e.currentTarget.dataset;
      if (op === 'add') {
        this.addCart(item)
      } else {
        this.reduceCart(item);
        if (this.data.num === 0) {
          this.setData({showDetail: false})
        }
      }
    }
  }
});
